import sys
import os.path

def permutations(m):
    """
    >>> permutations("abc")
    ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
    """
    if len(m)==1:
        return [m]
    else:
        ret = []
        for i, c in enumerate(m):
            nw = m[:i] + m[i+1:]
            ret.extend(map(lambda x: c+x, permutations(nw)))
        return ret

def fact(n):
    """
    >>> fact(0)
    1
    >>> fact(1)
    1
    >>> fact(5)
    120
    """
    res = 1
    while n:
        res *= n
        n -= 1
    return res


if len(sys.argv) != 2:
    print "Usage: %s word" % os.path.basename(sys.argv[0])
elif sys.argv[1]=='-t':
    import doctest
    doctest.testmod(verbose=True)
else:
    LIMIT = 9 #beyond, it's far too slow (for my Core i5).
    l = len(sys.argv[1])
    ct = fact(l)
    print "Count: %d" % ct,
    if l>LIMIT:
        print " - too much!"
    else:
        print "" #end the line...
        res = permutations(sys.argv[1])
        for x in res:
            print "Permutation: %s" % x
